package com.ruoyi.glsims.service.impl;

import com.ruoyi.glsims.mapper.ProveMapper;
import com.ruoyi.glsims.service.CountService;
import com.ruoyi.glsims.vo.LineVO;
import com.ruoyi.glsims.vo.PieVO;
import com.ruoyi.glsims.vo.PieValObj;
import com.sun.jmx.remote.internal.ArrayQueue;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * IntelliJ IDEA
 * project: graduate-leaving-school-information-management-system
 *
 * @author shimi
 * @since 2023/9/12
 */
@Service
public class CountServiceImpl implements CountService {

    @Resource
    private ProveMapper mapper;

    @Override
    public PieVO renderPieVO() {
        PieVO vo = new PieVO();
        vo.setDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        ArrayList<PieValObj> list = new ArrayList<PieValObj>(){{
            add(new PieValObj("未通过", mapper.countUnPass()));
            add(new PieValObj("未审核", mapper.countUnCheck()));
            add(new PieValObj("已通过", mapper.countPassed()));
        }};
        vo.setData(list);
        return vo;
    }

    @Override
    public LineVO renderLineVO() {
        final int days = 7;
        List<String> dates = new ArrayQueue<>(days);
        List<Integer> numbers = new ArrayQueue<>(days);
        List<String> dates2 = new ArrayQueue<>(days);
        List<Integer> numbers2 = new ArrayQueue<>(days);
        LineVO vo = new LineVO(dates2,numbers2);
        String todayStr = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        for (int i = 0; i < days; ++i) {
            dates.add(todayStr);
            numbers.add(mapper.countApplyByDay(todayStr));
            if (i == 6) break;
            todayStr = mapper.dateSub(todayStr,1);
        }
        for (int i = days - 1; i >= 0; i--) {
            dates2.add(dates.get(i));
            numbers2.add(numbers.get(i));
        }
        return vo;
    }
}
